//
//  MYBaseUserInfoCell.swift
//  MuYing
//
//  Created by tbb on 2019/7/24.
//  Copyright © 2019 TBB. All rights reserved.
//

import UIKit

@objc protocol MYBaseUserInfoCellDelegate:NSObjectProtocol {
    
    func moreActionIndexPath(_ indexPath:NSIndexPath);
    
}

class MYBaseUserInfoCell: YQTableViewBaseCell {
    
    @objc weak var delegate:MYBaseUserInfoCellDelegate?;
    @objc var indexPath:NSIndexPath?
    
    @objc lazy var userIcon: UIImageView = {
        let userIcon = UIImageView() ;//image: UIImage(named: "Login_logo_icon")
        userIcon.contentMode = .scaleAspectFill;
        userIcon.layer.cornerRadius = 14;//userIcon.width / 2.0;
        userIcon.clipsToBounds = true;
        userIcon.backgroundColor = appThemeColor;
        return userIcon;
    }()
    
    @objc lazy var nameLb: UILabel = {
        let nameLb = UILabel();
        nameLb.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        nameLb.textColor = appMainTitleColor;
        nameLb.text = "---";
        return nameLb;
    }()
    
    @objc lazy var rightBtn: UIButton = {
        let rightBtn = UIButton(type: .custom);
        rightBtn.titleLabel?.font = UIFont.systemFont(ofSize: 12, weight: .medium);
        rightBtn .setTitleColor(appThemeColor, for: .normal);
        rightBtn.addTarget(self, action: #selector(moreAction(_ :)), for: .touchUpInside)
        return rightBtn;
    }()
    
    @objc func moreAction(_ sender:UIButton) {

        if let delegate = self.delegate, delegate.responds(to: Selector(("moreActionIndexPath:"))), let indexPath = self.indexPath {
            delegate.moreActionIndexPath(indexPath);
        }
        
    }

    override func layoutSubviews() {
        super.layoutSubviews();
        
        self.contentView.addSubview(self.userIcon);
        self.userIcon.mas_makeConstraints { (make) in
            make?.left.mas_equalTo()(12);
            make?.centerY.mas_equalTo()(0);
            make?.size.mas_equalTo()(CGSize(width: 28, height: 28));
        }
        
        self.contentView.addSubview(self.nameLb);
        self.nameLb.mas_makeConstraints { (make) in
            make?.left.mas_equalTo()(self.userIcon.mas_right)?.mas_equalTo()(8);
            make?.centerY.mas_equalTo()(0);
            make?.height.mas_equalTo()(20);
        }
        
        self.contentView.addSubview(self.rightBtn);
        self.rightBtn.mas_makeConstraints { (make) in
            make?.right.mas_equalTo()(-12);
            make?.centerY.mas_equalTo()(0);
            make?.height.mas_equalTo()(24);
        }
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
